#!/bin/sh
# Copyright 2011 Argos <argos66@gmail.com>
set -e
. /usr/share/debconf/confmodule
db_get php-clamav/edit_phpini || true

PHP_CONF_PATH=/etc/php5

if [ "$RET" = true ]; then
#Deletion of older php-clamav method
    for ppkg in apache cli cgi apache2; do
        if [ -f $PHP_CONF_PATH/$ppkg/php.ini ]; then
            if grep -q "clamav.so" $PHP_CONF_PATH/$ppkg/php.ini; then
                phptemp=`mktemp`
                sed "s/extension=clamav.so//;s/clamav\..*//;s/\[clamav\]//;" < $PHP_CONF_PATH/$ppkg/php.ini > $phptemp
                mv -f $phptemp $PHP_CONF_PATH/$ppkg/php.ini
                rm -f $phptemp
            fi
        fi
    done
#Create clamav.ini file
    printf "extension=clamav.so\n" > $PHP_CONF_PATH/conf.d/clamav.ini
    printf "[clamav]\n" >> $PHP_CONF_PATH/conf.d/clamav.ini
    printf "clamav.dbpath=\"/var/lib/clamav\"\n" >> $PHP_CONF_PATH/conf.d/clamav.ini
    printf "clamav.maxreclevel=16\n" >> $PHP_CONF_PATH/conf.d/clamav.ini
    printf "clamav.maxfiles=10000\n" >> $PHP_CONF_PATH/conf.d/clamav.ini
    printf "clamav.maxfilesize=26214400\n" >> $PHP_CONF_PATH/conf.d/clamav.ini
    printf "clamav.maxscansize=104857600\n" >> $PHP_CONF_PATH/conf.d/clamav.ini
    printf "clamav.keeptmp=0\n" >> $PHP_CONF_PATH/conf.d/clamav.ini
    printf "clamav.load_db_on_startup=0\n" >> $PHP_CONF_PATH/conf.d/clamav.ini
    printf "clamav.tmpdir=\"/tmp\"\n" >> $PHP_CONF_PATH/conf.d/clamav.ini

    echo "Configure clamav.ini files....."
fi

#DEBHELPER#

